<?php
echo $this->headLink()->prependStylesheet($this->baseUrl().'/css/product_enquiry.css');
echo $this->headLink()->prependStylesheet($this->baseUrl().'/css/datatables/demo_page.css');
echo $this->headLink()->prependStylesheet($this->baseUrl().'/css/datatables/demo_table_jui.css');
echo $this->headLink()->prependStylesheet($this->baseUrl().'/css/datatables/demo_table.css');
echo $this->headLink()->prependStylesheet($this->baseUrl().'/css/ui-darkness/jquery-ui-1.8.16.custom.css');
echo $this->headScript()->appendFile($this->baseUrl().'/js/jquery-1.6.2.min.js');
echo $this->headScript()->appendFile($this->baseUrl().'/js/jquery-ui-1.8.16.custom.min.js');
echo $this->headScript()->appendFile($this->baseUrl().'/js/datatables/jquery.dataTables.min.js');

?>
<script type="text/javascript">
$(document).ready(function(){
	$('#table1').dataTable( {
		"bJQueryUI": true
	});
	$('#table2').dataTable( {
		"bJQueryUI": true
	});
});

$(function() {
	$("#dialog:ui-dialog").dialog("destroy");
	$("#dialog-confirm1").dialog({
		resizable: false,
		modal: true,
		show: "blind",
		hide: "explode",
		buttons: {
			OK: function() {
				$(this).dialog("close");
			}
		}
	});
	$("#dialog-confirm2").dialog({
		resizable: false,
		modal: true,
		show: "blind",
		hide: "explode",
		buttons: {
			OK: function() {
				$(this).dialog("close");
			}
		}
	});
	$("#dialog-confirm3").dialog({
		resizable: false,
		modal: true,
		autoOpen: false,
		show: "blind",
		hide: "explode",
		buttons: {
			OK: function() {
				$(this).dialog("close");
			}
		}
	});

	$(".error").click(function() {
		$("#dialog-confirm3").dialog("open");
		return false;
	});
});

</script>
<?php
$this->title = "Product Enquiry";
$this->headTitle($this->title);
?>
<h1><a href="<?php echo $this->url(array('controller'=>'index', 'action'=>'index'), null, true); ?>">Home</a> > <?php echo $this->escape($this->title); ?></h1>
<div class="cont">
<?php echo $this->form;?>
<div class="gap"></div>
<div class="table">
<table id="table1">
<thead>
<tr>
	<th>Product No</th>
	<th>Name</th>
	<th>Type</th>
	<th>Description</th>
	<th>price</th>
	<th>Quantity</th>
	<th>LeadTime</th>
	<th>Department Name</th>
	<th>Supplier No</th>
	<th>Catalogue</th>
	<th>Alt</th>
	<th>Link</th>
	
	
</tr>
</thead>
<tbody>
<?php foreach($this->products as $product) { 
        
		$stock = $product->prod_quantity;
		
?>
<tr>
	<td><?php echo $this->escape($product->prod_no); ?></td>
	<td><?php echo $this->escape($product->prod_name); ?></td>
	<td><?php echo $this->escape($product->prod_type); ?></td>
	<td><?php echo $this->escape($product->prod_description); ?></td>
	<td><?php echo $this->escape($product->prod_price); ?></td>
	<td><?php echo $this->escape($product->prod_quantity);?></td>
	<td><?php echo $this->escape($product->prod_leadtime); ?></td>
	<td><?php echo $this->escape($product->dep_name); ?></td>
	<td><?php echo $this->escape($product->supplier_no); ?></td>
	<td><a href="<?php echo $this->url(array('controller'=>'product', 'action'=>'request', 'prod_no'=>$product->prod_no), null, true); ?>">Apply</a></td>
	<td><a href ="<?php echo $this->url(array('controller'=>'product', 'action'=>'enquiry', 'prod_no'=>$product->prod_no, 'prod_type'=>$product->prod_type, 'dep_no'=>$product->dep_no, 'alt'=>"yes"), null, true);?>">Alt</a></td>
	<td><a class="link<?php if ($stock == 0) { echo " error"; } ?>" href="<?php echo $this->url(array('controller'=>'order', 'action'=>'cart', 'prod_no'=>$product->prod_no, 'prod_qty'=>$stock), null, true); ?>">Order</a>
		<a href="<?php echo $this->url(array('controller'=>'cep', 'action'=>'add', 'prod_no'=>$product->prod_no, 'dep_no'=>$product->dep_no, 'prod_quantity'=>$stock), null, true); ?>" class="link">Enquiry</a>
	</td>
</tr>
<?php } ?>

</tbody>
</table>
</div>

<?php if (count($this->products) == 0) { ?>
<div id="dialog-confirm1" title="ERROR">
<p>No matching data!</p>
</div>
<?php } ?>

<?php if ($this->altGo == "yes") { ?>
<div class="table">
<table id="table2">
<thead>
<tr>
	<th>Reason</th>
	<th>Product No</th>
	<th>Name</th>
	<th>Type</th>
	<th>Description</th>
	<th>Org Price</th>
	<th>Dis Price</th>
	<th>Quantity</th>
	<th>LeadTime</th>
	<th>Department Name</th>
	<th>Supplier No</th>
	<th>Catalogue</th>
</tr>
</thead>
<tbody>
<?php $flag = 0;
foreach($this->alternatives as $alt) 
{
	if($this->index != $alt->prod_no)
	{
		$flag++;
	?>
<tr>      
	<td><?php if ($alt->prod_sale_price < $alt->prod_price)	{ echo "Discount"; } else { echo "Type"; } ?></td>
	<td><?php echo $this->escape($alt->prod_no); ?></td>
	<td><?php echo $this->escape($alt->prod_name); ?></td>
	<td><?php echo $this->escape($alt->prod_type); ?></td>
	<td><?php echo $this->escape($alt->prod_description); ?></td>
	<td><?php echo $this->escape($alt->prod_price); ?></td>
	<td><?php echo $this->escape($alt->prod_sale_price);?>
	<td><?php echo $this->escape($alt->prod_quantity); ?></td>
	<td><?php echo $this->escape($alt->prod_leadtime); ?></td>
	<td><?php echo $this->escape($alt->dep_name); ?></td>
	<td><?php echo $this->escape($alt->supplier_no); ?></td>
	<td><a href="<?php echo $this->url(array('controller'=>'product', 'action'=>'request', 'prod_no'=>$alt->prod_no), null, true); ?>">Apply</a></td>
</tr>

<?php
	}
}?>
</tbody>
</table>
</div>
<?php if ($flag == 0 && $this->altGo == "yes") { ?>
<div id="dialog-confirm2" title="ERROR">
<p>No Alternatives!</p>
</div>
<?php } 
}?>
</div>
<div id="dialog-confirm3" title="ERROR">
<p>Out of stock!!</p>
<p>Please record Customer Enquiry Problem.</p>
</div>

